﻿
using UnityEngine;
using UnityEngine.EventSystems;

namespace MFramework
{
    public delegate void PointerEventHandler(PointerEventData eventData);

    public class UIEventListener : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IDragHandler
    {
        public event PointerEventHandler PointerClick;
        public event PointerEventHandler PointerDown;
        public event PointerEventHandler PointerUp;
        public event PointerEventHandler Drag;

        public void OnPointerClick(PointerEventData eventData)
        {
            if (eventData.selectedObject != null)
                PointerClick?.Invoke(eventData);
        }

        public void OnPointerDown(PointerEventData eventData)
        {
            if (eventData.selectedObject != null)
                PointerDown?.Invoke(eventData);
        }

        public void OnPointerUp(PointerEventData eventData)
        {
            if (eventData.selectedObject != null)
                PointerUp?.Invoke(eventData);
        }

        public void OnDrag(PointerEventData eventData)
        {
            if (eventData.selectedObject != null)
                Drag?.Invoke(eventData);
        }
    }
}
